library SelectULCommand initializer init requires LegacySystem, PlayerSelectsHeroCommand, LegacyHumanAbilities

	private function Trig_Player_Selects_IUL_Conditions takes nothing returns boolean
		if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'H00J' ) ) then
			return false
		endif
		return true
	endfunction


	private function Trig_Player_Selects_IUL_Actions takes nothing returns nothing

		local unit u = GetTriggerUnit()
		local player p = GetOwningPlayer(u)
		local integer id = GetConvertedPlayerId(p)

		call putUnit(p,"hero", u)

		call setPlayerDataInteger(p,"pistol_ammo",8)
		call setPlayerDataInteger(p,"pistol_type",0)
		call setPlayerDataBoolean(p,"pistol_reload",false)
	   
		call SetUnitUserData(u,50)
	   
		set udg_HeroAvailable[9] = 0
			
		set udg_PlayerIcon[id] = "ReplaceableTextures\\CommandButtons\\BTN_Unit_MarineLeader.blp"
		set udg_KillFactor[id] = 0.9

		call UnitAddItemById(u,'I00M') 
		call UnitAddItemById(u,'I006')
		call UnitAddItemById(u,'I006')
		
		set udg_KillFactor[id] = 0.9
		set udg_ReloadTime[id] = 5.0
		
		call SetUnitAbilityLevel(u,'A000', 2) // sprint level 2 for RM/UL/DO
		
		call AddPrimaryAmmo(u, 10, 50)
		call RegisterAmmoAutoReloadListener(u)
		call RegisterAmmoEmptyListener(u)
		
		call InitHero(u)
		
		if GetI("player mos", id) == 1 then
			call ModifyHeroSkillPoints( u, bj_MODIFYMETHOD_ADD, 1 )
		endif
		
		
		set u = null
		set p = null
		
		if( udg_HeroAvailable[9] <= 0 ) then
			call DisableTrigger(GetTriggeringTrigger())
		endif

	endfunction

	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger(  )
		call TriggerRegisterEnterRectSimple( t, GetPlayableMapRect() )
		call TriggerAddCondition( t, Condition( function Trig_Player_Selects_IUL_Conditions ) )
		call TriggerAddAction( t, function Trig_Player_Selects_IUL_Actions )
	endfunction


endlibrary